{include('Layout/header')}

<script charset="utf-8" src="{$host}statics/editor/kindeditor.js"></script>
<script charset="utf-8" src="{$host}statics/editor/lang/zh_CN.js"></script>
<script>
    KindEditor.ready(function(K) {
        window.editor = K.create('#editor_id', {
            width : '100%',
            height: '450px',
            uploadJson : "{\Rexzy::url('admin/artupload')}",
            filterMode: true,
        });
    });
</script>



<div class="row row-bgcolor">
    <div class='col-md-12 content-title'>
        <h3>撰写新文章</h3>
    </div>
    <div class='col-md-12 content col-md-offset-1'>
            <form>
                <div class="col-md-8 form-group">
                    <input type="text" class="form-control art-title" id="art_title" name="arttitle" placeholder='标题'/>
                    <div>
                        <label for="outline">文章概要</label>
                        <textarea class="form-control" rows="5" id="outline" name="ourline"></textarea>
                        <p class="outline-note">文章概要用于在博客主页显示每篇文章的简介</p>
                    </div>
                    <textarea id="editor_id" name="content" style="width:100%;height:300px;">
                    </textarea>
                    <button type="submit" class="btn btn-info issueart" id='addart-btn'>发布文章</button>
                </div>
                <div class='col-md-2 artwrite-options'>
                    <ul class='main-option'>
                        <li><a href='#' class='main-option-choice'>选项</a></li>
                    </ul>
                    <div class='artwrite-act-content'>
                        <div class="form-group">
                            <label for="issuetime">发布日期</label>
                            <input type="text" class="form-control datepicker" id="issue_time" name="issuetime" data-date-format="yyyy-mm-dd" size="16"/>
                        </div>  
                        <div>
                            <label for="time">分类</label>
                            <ul class='artsort-choice'>
                                {php} 
                                    function sortChoice( $id, $artsort ) {
                                        $sorts = $artsort->selectAll( 'sortid, name, parent, children', "where parent = $id" );
                                        foreach ( $sorts as $key => $value ) {
                                        echo "<li><label class='checkbox-inline'><input class='artwrite-sortchoice-box' type='checkbox' value='" . $value['sortid'] . "'>" . $value['name'] . "</label></li>";
                                            if ( $value['children'] > 0 ) {
                                                sortChoice( $value['sortid'], $artsort );
                                            }
                                        }
                                    }
                                    sortChoice( 0, $artsort );
                                {/php}
                            </ul>
                        </div>
                    </div>
                </div>
            </form>
    </div>
</div>

<script>
    $(function() {
        $("button[type='submit']").click( function() {
            editor.sync();
            var sortval = new Array();
            $("input[class='artwrite-sortchoice-box']").each( function() {
               if ( this.checked == true ) {
                   sortval.push( this.value); 
               } 
            }); 
            sortval = sortval.join(",");
            var data = {
                art: $('#editor_id').val(),
                arttitle: $('#art_title').val(),
                sortval: sortval,
                date: $('.datepicker').val(),
                outline: $("#outline").val()
            };

            var btn = $("button[type='submit']").button('loading');
            $.post( url('admin/artissue'), data, function( result ) {
                btn.button('reset');
                if ( result.issueResult == true ) {
                    location = url('admin/artlist');
                } else {
                    $('body').append("<div class='alert alert-warning' style='margin-top:15px;padding: 70px 20px;position: absolute;width: 350px;color: #4C4A4A;background-color: #F1F1F1; border-color: #9E9E9E;    left: 45%; top: 70%;'><p>" + result.error + "</p><button type='button' class='close' data-dismiss='alert' style='padding: 0px 15px;border: 1px solid #B9B9B9;position: absolute;bottom: 5px;right: 10px;background-color: #D4D4D4; opacity: 1;color: #616161;'>&times;</button></div>");
                }
            },'json');
            return false;
        });
    });
</script>




<!--<script>
    $(function() {
        $(".main-option-choice").each( function( i ) {
            $(this).click( function() {
                $('.artwrite-act-content').hide().eq( i ).show();
            });
        }).eq(0).click();
    });
</script>-->
{include('Layout/footer')}